package spring.test3;

import com.blackhorse.service.AccountService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *利用Spring Aop完成之前转账案例的事务控制
 */
public class Demo4_AnillTransactionByAOP {
    private ApplicationContext applicationContext;

    /**
     *利用Spring Aop完成之前转账案例的事务控制
     * 用到的切面类：com.blackhorse.anlis.anli_transaction_aop.TransactionByAOP
     * 业务逻辑类：com.blackhorse.anlis.anli_transaction.service.AccountServiceImpl
     * Spring配置文件：anlis/ac_anli_transaction_aop.xml
     */
    @Test
    public void testAopTransaction() {
        String xmlPath = "anlis/anli_tx_aop/ac_anli_transaction_aop.xml";
        applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        AccountService service = applicationContext.getBean("anliAccountServiceWithNoTransaction", AccountService.class);
        service.transter("张三", "李四", -100);
    }

    /**
     *利用Spring Aop完成之前转账案例的事务控制（注解配置）
     * 用到的切面类：com.blackhorse.anlis.anli_transaction_aop.TransactionByAOP_Annotation
     * 业务逻辑类：com.blackhorse.anlis.anli_transaction.service.AccountServiceImpl
     * Spring配置文件：anlis/ac_anli_transaction_aop_annotation.xml
     */
    @Test
    public void testAopTransactionAnnotation() {
        String xmlPath = "anlis/anli_tx_aop/ac_anli_transaction_aop_annotation.xml";
        applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        AccountService service = applicationContext.getBean("anliAccountServiceWithNoTransaction", AccountService.class);
        service.transter("张三", "李四", 100);
    }
}
